<template>
    <s-box title="技术热门新闻" ref="loading">
        <div class="chart-box">
            <div class="swiper-container" id="announcement" ref="announcement" >
                <div class="swiper-wrapper">
                    <div class="swiper-slide" v-for="item in list" :key="item.id">
                        <a class="morelist-item" :href="item.url" target="_blank">
                            <div class="name">{{item.title}}</div>
                            <span class="date">{{item.publishtime}}</span>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </s-box>
</template>
<script>

import delegate from '../js/event.js';
import Swiper from "swiper";
import "swiper/dist/css/swiper.min.css";
import data3 from "./sweiper.json";
import mixin from '../js/mixin.js';
export default {
    mixins:[mixin],
    data() {
        return {
           list:[],
           data3
        }
    },
    mounted(){
        this._initMethod();
    },
    beforeDestroy(){
         // 解除事件绑定
         delegate.$off('s-resize',this._initSwiper)
         delegate.$off('s-search',this._search)
    },
    methods: {
        _initMethod() {
            delegate.$on('s-search',this._search);
            delegate.$on('s-resize',this._initSwiper);
        },
        _search(text) {
            console.log(text)
        },
        _initSwiper() {
            this.$nextTick(()=>{
              this.$refs.loading.show();
            });
            this._getNewslist();
        },
        _getNewslist(){
            if(!this.navCurrentId) return;
            this.api({
                    url: "newtechanalyse/latestTechnologyTrends",
                    method: "post",
                    data:`topicId=${this.navCurrentId}`
            }).then(data => {
                this.$refs.loading.hide();
                this.list = data;
                this.$nextTick(() => {
                    if(this.announcementSwiper) {
                        this.announcementSwiper.destroy();
                        this.announcementSwiper = null;
                    }
                    if(!this.announcementSwiper){
                        let $this = this;
                        this.announcementSwiper = new Swiper(this.$refs.announcement, {
                            direction: "vertical",
                            slidesPerView: "11",
                            loop: true,
                            autoplay: {
                                delay: 500 //1秒切换一次
                            }
                        });
                        this.$refs.announcement.onmouseenter = function() {
                            $this.announcementSwiper.autoplay.stop();
                        };
                        this.$refs.announcement.onmouseleave = function() {
                            $this.announcementSwiper.autoplay.start();
                        };
                    }

                });
            }).catch((error) =>{ this.$refs.loading.hide()})
        }
    },
}
</script>
<style lang="scss" scoped>
  .chart-box{
      position: relative;
      padding-top: 139.5%;
  }
.swiper-container {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
}
.swiper-slide {
  display: flex;
  align-items: center;
  overflow: hidden;
  background: #04074b;
  &:nth-child(2n){
    background:#0f136c;
  }
}


.morelist-item {
  position: relative;
  display: block;
  flex: 1;
  overflow: hidden;
  padding: 0 15px;
  box-sizing: content-box;
  &::before{
      position: absolute;
      content: '';
      width: 6px;
      height: 6px;
      border-radius: 50%;
      background-color: #f59f00;
      left: 10px;
      top: 50%;
      transform: translateY(-50%);
  }
  .name {
    padding-left: 15px;
    padding-right: 100px;
    color: #fff;
    font-size: 14px;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .date {
    position: absolute;
    top: 0;
    right: 10px;
    color: #fff;
    font-size: 12px;
  }
}
</style>
